# coding : UTF-8
import threading
import re
import time
import urllib
import urllib.request
import string

res_a = 0
res_b = 0
res_c = 0

def get_home_page(url):
    url_list = []
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
    request = urllib.request.Request(url=url, headers=headers)
    html = urllib.request.urlopen(request).read()
    html = html.decode('gbk')
    items = re.findall(re.compile(r'<a class="lady-name" href=".+?user_id=(.+?)" target="_blank">(.+?)</a>\r\n\t+<em><strong>(.+?)</strong>岁</em>\r\n\t+<span>(.+?)</span>'), html)
    for item in items :
        url_list.append(item)
    return url_list

def get_person_info(user_id):
    url = "https://mm.taobao.com/self/album/open_album_list.htm?_charset=utf-8&user_id%20=" + user_id
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
    request = urllib.request.Request(url=url, headers=headers)
    html = urllib.request.urlopen(request).read()
    html = html.decode('gbk')
    items = re.findall(re.compile(r'<a href="(.+?)" >相册</a>'), html)
    #urllib.request.urlretrieve(url_list[0], './download/%s' % name_list[0])

if __name__ == '__main__':
    for i in range(1,10):
        my_ulist = get_home_page("https://mm.taobao.com/json/request_top_list.htm?page=%d" %i)
        if my_ulist != "":
            for purl in my_ulist:
                print(purl[1],purl[2],purl[3],purl[0])
                get_person_info(purl[0])

